<html>
<head>
    <title>复制图片到剪切板</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <div id="imgDyaminQrcodeContent">
        <div class="zf-mass-code-img">
            <img id="imgDyaminQrcode" src="https://dss0.baidu.com/73t1bjeh1BF3odCf/it/u=1163364929,207445095&fm=85&s=33D2E9374502454B0C6DB8CA01005033" alt="" >
        </div>
        <a id="linkCopyImage" href="#">复制图片</a>
    </div>
</body>
<script type="text/javascript">
    var SelectText = function (element) {
        var doc = document;
        if (doc.body.createTextRange) {
            var range = document.body.createTextRange();
            range.moveToElementText(element);
            range.select();
        } else if (window.getSelection) {
            var selection = window.getSelection();
            var range = document.createRange();
            range.selectNodeContents(element);
            selection.removeAllRanges();
            selection.addRange(range);
        }
    }
 
    //复制图片
    var copyImage = document.getElementById("linkCopyImage");
    copyImage.onclick = function(e){
        //Make the container Div contenteditable
        $(".zf-mass-code-img").attr("contenteditable", true);
        //Select the image
        SelectText($('.zf-mass-code-img').get(0));
        //Execute copy Command
        //Note: This will ONLY work directly inside a click listenner
        document.execCommand('copy');
        //Unselect the content
        window.getSelection().removeAllRanges();
        //Make the container Div uneditable again
        $('.zf-mass-code-img').removeAttr("contenteditable");
        //Success!!
        alert('复制图片成功');
    }
 
</script>
</html>